/**
 * @Description CustomerOrderDailyDataServiceImpl.java
 * @author xu_cc [18724000100@163.com]
 * @date 创建时间：2018年1月11日 下午9:00:01
 */
package com.solution.admin.report.service.impl;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.solution.admin.report.dao.CustomerOrderDailyDataDao;
import com.solution.admin.report.entity.CustomerOrderDailyDataEntity;
import com.solution.admin.report.service.CustomerOrderDailyDataService;
import com.solution.common.dao.BaseDao;
import com.solution.common.service.impl.BaseServiceImpl;

/**
 * 每日统计数据
 * 
 * @author xu_cc
 * @date 创建时间：2018年1月11日 下午9:00:20
 */
@Service
public class CustomerOrderDailyDataServiceImpl extends BaseServiceImpl<CustomerOrderDailyDataEntity> implements CustomerOrderDailyDataService {

	@Autowired
	CustomerOrderDailyDataDao customerOrderDailyDataDao;

	@Override
	protected BaseDao<CustomerOrderDailyDataEntity> getDao() {
		return customerOrderDailyDataDao;
	}

	@Override
	public long insert(CustomerOrderDailyDataEntity dailyData) {
		return customerOrderDailyDataDao.insert(dailyData);
	}

	@Override
	public CustomerOrderDailyDataEntity getDailyDataByDate(String dateStr) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("date", dateStr);
		CustomerOrderDailyDataEntity dailyData = customerOrderDailyDataDao.getDailyDataByDate(paramMap);
		// 取不到这一天的数据，那就是 0
		if (null == dailyData) {
			SimpleDateFormat paramFormat = new SimpleDateFormat("yyyy-MM-dd");
			Date date = null;
			try {
				date = paramFormat.parse(dateStr);
			} catch (ParseException e) {
				e.printStackTrace();
			}
			dailyData = new CustomerOrderDailyDataEntity(date, dateStr, 0, 0, 0, BigDecimal.ZERO);
		}
		return dailyData;
	}

	/**
	 * 获取本月订单数量
	 * @param thisMonth
	 * @param nextMonth
	 * @return
	 * @author xkl
	 * @date 2018年2月12日 下午2:49:06
	 */
	@Override
	public Integer getPresentMonthOrderCount(String thisMonth, String nextMonth) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("thisMonth", thisMonth);
		paramMap.put("nextMonth", nextMonth);
		return customerOrderDailyDataDao.getPresentMonthOrderCount(paramMap);
	}

}
